package com.jihox.abookpro.adapter;

import java.util.List;

import com.jihox.abookpro.domain.AddressListItem;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AddressAdapter extends BaseAdapter {

	private Context context;
	private List<AddressListItem> myList;

	public AddressAdapter(Context context, List<AddressListItem> myList) {
		this.context = context;
		this.myList = myList;
	}

	public int getCount() {
		return myList.size();
	}

	public Object getItem(int position) {
		return myList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		AddressListItem myListItem = myList.get(position);
		return new AddressAdapterView(this.context, myListItem);
	}

	public class AddressAdapterView extends LinearLayout {
		public static final String LOG_TAG = "MyAdapterView";
		public TextView valueView = null;

		public AddressAdapterView(Context context, AddressListItem myListItem) {
			super(context);
			this.setOrientation(HORIZONTAL);

			LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
			params.setMargins(1, 25, 1, 25);

			valueView = new TextView(context);
			valueView.setText(myListItem.getValue());
			addView(valueView, params);

			LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
			params2.setMargins(1, 1, 1, 1);

			TextView pcode = new TextView(context);
			pcode.setText(myListItem.getCode());
			addView(pcode, params2);
			pcode.setVisibility(GONE);

		}

	}

}
